package com.vision.mapper;

import com.vision.pojo.entity.User;
import com.vision.pojo.vo.ChatUserVO;
import com.vision.pojo.vo.UserInfoVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 通过邮箱或者手机号注册用户
     * @param user 用户
     */
    void insertUserByPhoneOrEmail(User user);

    /**
     * 通过 id 或 username 修改用户
     * @param user 用户
     */
    void updateUserBaseInfo(User user);

    /**
     * 通过 id 更新用户邮箱
     * @param id 用户 id
     * @param email 用户邮箱
     */
    @Update("update vs_user set email = #{email},update_time = now() where id = #{id}")
    void updateEmail(Integer id, String email);

    /**
     * 通过 id 更新用户手机号
     * @param id 用户 id
     * @param phone 用户手机号
     */
    @Update("update vs_user set phone = #{phone},update_time = now() where id = #{id}")
    void updatePhone(Integer id, String phone);

    /**
     * 通过 id 更新用户密码
     * @param id 用户 id
     * @param password 用户密码
     */
    @Update("update vs_user set password = #{password},update_time = now() where id = #{id}")
    void updatePassword(Integer id, String password);

    /**
     * 通过手机号查询用户
     * @param phoneOrEmail 手机号或邮箱
     * @return 用户
     */
    @Select("select id, username, password, nickname, gender, phone, email, avatar, create_time, update_time, role, description from vs_user where phone = #{phone} or email = #{email}")
    User selectByPhoneOrEmail(String phoneOrEmail);

    /**
     * 通过用户名查询用户
     * @param username 用户名
     * @return 用户
     */
    @Select("select id, username, password, nickname, gender, phone, email, avatar, create_time, update_time, role, description from vs_user where username = #{username}")
    User selectUserByUsername(String username);

    /**
     * 通过 email 查询用户
     * @param email 用户邮箱
     * @return 用户
     */
    @Select("select id, username, password, nickname, gender, phone, email, avatar, create_time, update_time, role, description from vs_user where email = #{email}")
    User selectUserByEmail(String email);

    /**
     * 通过 phone 查询用户
     * @param phone 用户手机号
     * @return 用户
     */
    @Select("select id, username, password, nickname, gender, phone, email, avatar, create_time, update_time, role, description from vs_user where phone = #{phone}")
    User selectUserByPhone(String phone);

    /**
     * 通过 id 查询用户
     * @param id 用户 id
     * @return 用户
     */
    @Select("select id, username, password, nickname, gender, phone, email, avatar, create_time, update_time, role, description from vs_user where id = #{id}")
    User selectUserById(Integer id);

    /**
     * 通过用户 id 查询用户信息
     * @param userId 用户 id
     * @param nickname 用户昵称
     * @return
     */
    List<UserInfoVO> selectUserList(Integer userId, String nickname);
}
